package com.chenille.tools.util

import android.content.Context
import android.widget.Toast
import com.chenille.tools.util.ToastUtil
import android.view.LayoutInflater
import android.view.View
import com.chenille.tools.R
import android.widget.TextView

/**
 * @author couldxtra
 * @version v1.0
 * @desc
 * @contact cnhttt@163.com
 * @time 2022/3/7 11:58 下午
 * @update: [序号:1][日期YYYY-MM-DD:2022/3/7] [更改人姓名:F][变更描述:create]
 */
object ToastUtil {
    /**
     * 系统的Toast
     *
     * @param info
     */
    fun showToast(context: Context?, info: String?) {
        Toast.makeText(context, info, Toast.LENGTH_SHORT).show()
    }

    /**
     * 各种类型的 Toast
     *
     * @param info
     * @param type
     */
    fun showCus(context: Context?, info: String?, type: Type?) {
        val toast = Toast(context)
        var view: View? = null
        when (type) {
            Type.POINT ->                 // 提示型Toast
                view = LayoutInflater.from(context).inflate(R.layout.layout_toast_point, null)
            Type.SUCCEED ->                 // 操作成功Toast
                view = LayoutInflater.from(context).inflate(R.layout.layout_taost_succeed, null)
            Type.ERROR ->                 // 错误Toast
                view = LayoutInflater.from(context).inflate(R.layout.layout_toast_error, null)
            Type.WARNING ->                 // 警告Toast
                view = LayoutInflater.from(context).inflate(R.layout.layout_toast_warning, null)
            else -> {}
        }
        if (view != null) {
            val tv = view.findViewById<TextView>(R.id.toast_info)
            tv.text = info
            toast.duration = Toast.LENGTH_SHORT
            // 这里是修改Toast的显示位置
            // toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 120);
            toast.view = view
            toast.show()
        } else {
            showToast(context, info)
        }
    }

    /**
     * Toast类型
     */
   public  enum class Type {
        // 成功
        SUCCEED,  // 错误
        ERROR,  // 信息，通常
        POINT,  // 警告
        WARNING,
        OTHER
    }
}


